home *** CD-ROM | disk | FTP | other *** search
/ Champak 145 / (Vol 145) Dec 21 2011.iso / Games / kill-the-dragons.swf / scripts / frame_725 / DoAction.as
Encoding:
Text File  |  2011-12-21  |  1.5 KB  |  67 lines

  1. function Tween(mc, property, end, duration)
  2. {
  3.    this.duration = duration;
  4.    this.target = end;
  5.    this.start = mc[property];
  6.    this.mc = mc;
  7.    this.property = property;
  8. }
  9. function setTweens()
  10. {
  11.    var aa1 = 400;
  12.    var aa3 = random(maxDir) + aa1;
  13.    var aa2 = random(maxDir) + aa1;
  14.    xtween = new Tween(oppbossa1,"_x",random(300),aa3);
  15.    ytween = new Tween(oppbossa1,"_y",random(400),aa2);
  16.    xtween.onEnd = function()
  17.    {
  18.       setTweens();
  19.    };
  20. }
  21. Tween.prototype.step = function()
  22. {
  23.    if(!this.dontAnimate)
  24.    {
  25.    }
  26.    if(this.startTime == null)
  27.    {
  28.       this.startTime = getTimer();
  29.    }
  30.    var aa3 = getTimer() - this.startTime;
  31.    var aa2 = aa3 / this.duration;
  32.    aa2 = aa2 * aa2 * (3 - 2 * aa2);
  33.    this.mc[this.property] = this.start + (this.target - this.start) * aa2;
  34.    if(aa3 >= this.duration)
  35.    {
  36.       this.onEnd();
  37.       this.dontAnimate = true;
  38.    }
  39. };
  40. onEnterFrame = function()
  41. {
  42.    xtween.step();
  43.    ytween.step();
  44.    if(plyWithin == true && ply.thisEnergy > 0)
  45.    {
  46.       mouseX = _xmouse;
  47.       mouseY = _ymouse;
  48.    }
  49.    plyX = ply._x;
  50.    plyY = ply._y;
  51.    differenceX = mouseX - plyX;
  52.    differenceY = mouseY - plyY;
  53.    if(Math.abs(differenceX) > 1 && Math.abs(differenceY) > 1)
  54.    {
  55.       plyWalk = true;
  56.       ply._x += differenceX / plySpeed;
  57.       ply._y = ply._Y + differenceY / plySpeed;
  58.    }
  59.    else
  60.    {
  61.       plyWalk = false;
  62.    }
  63. };
  64. setTweens();
  65. startAnim.gotoAndPlay("start");
  66. stop();
  67.